package com.kuang.demo.controller;

import com.kuang.demo.bean.BaseRespVo;
import com.kuang.demo.bo.gh.CreateBrandBO;
import com.kuang.demo.bo.gh.UpdateBrandBO;
import com.kuang.demo.dto.BrandDTO;
import com.kuang.demo.mapper.StoreMapper;
import com.kuang.demo.service.StoreService;
import com.kuang.demo.vo.QueryBrandVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by 郭浩 on 2020/10/31 15:54
 */
@RestController
@RequestMapping("admin/brand")
public class BrandController {
    @Autowired
    StoreService storeService;
    @Autowired
    StoreMapper storeMapper;
    

    @GetMapping("list")
    //GET http://182.92.235.201:8083/admin/brand/list?page=1&limit=20&id=1046047&name=aaa&sort=add_time&order=desc HTTP/1.1
    //GET http://182.92.235.201:8083/admin/brand/list?page=1&limit=20                    &sort=add_time&order=desc HTTP/1.1
    public BaseRespVo brandList(Integer page, Integer limit, Integer id, String name, String sort, String order){
        QueryBrandVO queryBrandVO = new QueryBrandVO();
        //查询分页的信息
        Map<String, Object> brandInfo = storeService.queryBrandList(page, limit, id, name,sort, order);
        //查询总数
        int total = (int) brandInfo.get("total");
        List<BrandDTO> brandDTOList = (List<BrandDTO>) brandInfo.get("brandList");
        queryBrandVO.setItems(brandDTOList);
        queryBrandVO.setTotal(total);
        return BaseRespVo.ok(queryBrandVO);
    }
    @RequestMapping("read")
    public BaseRespVo readBrand(){
        return BaseRespVo.ok();
    }

    @PostMapping("create")
    //{"name":"test","desc":"test","floorPrice":"1111"}
    public BaseRespVo createBrand(@RequestBody CreateBrandBO createBrandBO){
        storeService.createBrand(createBrandBO);
        return BaseRespVo.ok();
    }
    @PostMapping("update")
    public BaseRespVo updateBrand(@RequestBody UpdateBrandBO updateBrandBO){
        storeService.updateBrand(updateBrandBO);
        return BaseRespVo.ok();
    }
    @PostMapping("delete")
    //因为前端更新删除传过来的对象属性一样，复用一哈
    public BaseRespVo deleteBrand(@RequestBody UpdateBrandBO deleteBrandBO){
        storeService.deleteBrand(deleteBrandBO);
        return BaseRespVo.ok();
    }


}
